package T4.EjemplosDelSwing.ejemplosgui;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class Frame9 extends JFrame implements ActionListener {

    private JPanel panel = new JPanel();
    private JButton azul;

    public Frame9() {
        setTitle("Hola!!!");
        setSize(500, 400);
        addWindowListener(new manejador9());
        Container contentpane = getContentPane();
        panel.setLayout(new BorderLayout());

        azul = new JButton("Azul");
        azul.addActionListener(this);
        Dimension tamano = new Dimension();
        tamano.height = 40;
        tamano.width = 100;
        azul.setPreferredSize(tamano);
        panel.add(azul, BorderLayout.SOUTH);

        contentpane.add(panel);
        panel.setBackground(Color.red);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        panel.setBackground(Color.blue);
    }
}

class manejador9 extends WindowAdapter {

    @Override
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}

public class Ejemplo9 {

    public static void main(String[] args) {
        JFrame frame = new Frame9();
        frame.setVisible(true);
    }
}
